<?php

namespace App\Edu\Models;

use App\Models\ApiSoftDeletes;
use App\Models\BaseModel;

use function GuzzleHttp\Promise\queue;

class EduQuestionModel extends BaseModel
{
    use ApiSoftDeletes;
    protected $table = 'edu_question';

    const TYPE_TITLE = 'title'; // 大题名称
    const TYPE_RADIO = 'radio'; // 单选题
    const TYPE_CHECKBOX = 'checkbox'; // 多选题
    const TYPE_FILL = 'fill'; // 填空题
    const TYPE_JUDGE = 'judge'; // 判断题
    const TYPE_ANALYSIS = 'analysis'; // 辨析题
    const TYPE_MATERIAL = 'material'; // 材料分析题

    const QUESTION_TYPE = [
        ['value' => self::TYPE_RADIO, 'label' => '单选题'],
        ['value' => self::TYPE_CHECKBOX, 'label' => '多选题'],
        ['value' => self::TYPE_FILL, 'label' => '填空题'],
        ['value' => self::TYPE_JUDGE, 'label' => '判断题'],
        ['value' => self::TYPE_ANALYSIS, 'label' => '辨析题'],
        ['value' => self::TYPE_MATERIAL, 'label' => '材料分析题'],
    ];

    /** 
     * 获取列表
     */
    public function getList($query, $pageSize = 10)
    {
        $db = $this->db('a');
        $where = [
        ];

        $fields = "a.*";
        if (isset($query['is_paper']) && $query['is_paper'] !== '') {
            $where['a.is_paper'] = $query['is_paper'];
        }
        $model = $db
            ->where($where)
            ->where('a.status', '<>', 2)
            ->selectRaw($fields);
        $orderByRaw = 'a.id desc';
        if (!empty($query['order_by'])) {
            $orderByRaw = "a." . $query['order_by'];
        }
        $pageData = $model
            ->orderByRaw($orderByRaw)
            ->paginate($pageSize)
            ->toArray();
        return $pageData;
    }
}
